package com.zhj.common.entity;


import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * 自定义返回格式
 * @param <T>
 */
@Data
public class ResponseData<T> {

    private T data;

    private Integer status;

    private String msg;

    public static <T> ResponseData<T> ok(T result) {
        return ok(result, "success");
    }

    public static <T> ResponseData<T> ok(T result, String msg) {
        ResponseData<T> responseData = new ResponseData<>();
        responseData.setData(result);
        responseData.setStatus(HttpStatus.OK.value());
        responseData.setMsg(msg);
        return responseData;
    }

    public static <T> ResponseData<T> failure(String msg) {
        ResponseData<T> responseData = new ResponseData<>();
        responseData.setMsg(msg);
        responseData.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        return responseData;
    }
}
